package com.frame.work.frame.deal.device0faa;

import com.alibaba.fastjson.JSONObject;
import com.frame.work.common.util.JsonToMqtt;
import com.frame.work.frame.deal.base.BaseFrame;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.Map;

import static com.frame.work.common.constant.CallType.TYPE_GET;
import static com.frame.work.common.constant.CallType.TYPE_SET;

/**
 *六路场景面板0FAA8A10
 */
@Data
public class LiuLuChangJingMianBan_0FAA8A10 extends BaseFrame{

    private Integer switchState;

    public LiuLuChangJingMianBan_0FAA8A10(String gatewayMac, String data,String type){
        //将基础数据进行处理
        super(gatewayMac,data);
        //根据不同类型进行判断
        if(TYPE_GET.equals(type)){
            LiuLuChangJingMianBan_0FAA8A10Get(gatewayMac,data);
        }else if (TYPE_SET.equals(type)){
            LiuLuChangJingMianBan_0FAA8A10Set(gatewayMac,data);
        }
    }



    public void LiuLuChangJingMianBan_0FAA8A10Get(String gatewayMac, String data){


        //处理此设备特有的数据
        String after0FAA = StringUtils.substring(data,22, 24);
        this.setSwitchState(-100);

        if ("FF".equals(after0FAA)){

            String sceneNumber = StringUtils.substring(data,data.length() - 2, data.length());

            //将actions信息放入json对象中
            Map <String,Object> actions = new HashMap();
            actions.put("controlType","SCENE_TRIGGER");
            actions.put("sceneNumber",sceneNumber);
            this.setActions(actions);

            //处理好的json对象
            String json = JSONObject.toJSONString(this);
            //将数据发送到mqtt队列中
            JsonToMqtt.sendMQTT(gatewayMac,json);

        } else if ("01".equals(after0FAA)){
            String sceneNumber = StringUtils.substring(data,data.length() - 2, data.length());

            //将actions信息放入json对象中
            Map <String,Object> actions = new HashMap();
            actions.put("controlType","SCENE_NUMBER_GET");
            actions.put("wayNumber",1);
            actions.put("sceneNumber",sceneNumber);
            this.setActions(actions);

            //处理好的json对象
            String json = JSONObject.toJSONString(this);
            //将数据发送到mqtt队列中
            JsonToMqtt.sendMQTT(gatewayMac,json);


        } else if ("02".equals(after0FAA)){
            String sceneNumber = StringUtils.substring(data,data.length() - 2, data.length());

            //将actions信息放入json对象中
            Map <String,Object> actions = new HashMap();
            actions.put("controlType","SCENE_NUMBER_GET");
            actions.put("wayNumber",2);
            actions.put("sceneNumber",sceneNumber);
            this.setActions(actions);

            //处理好的json对象
            String json = JSONObject.toJSONString(this);
            //将数据发送到mqtt队列中
            JsonToMqtt.sendMQTT(gatewayMac,json);


        } else if ("03".equals(after0FAA)){
            String sceneNumber = StringUtils.substring(data,data.length() - 2, data.length());

            //将actions信息放入json对象中
            Map <String,Object> actions = new HashMap();
            actions.put("controlType","SCENE_NUMBER_GET");
            actions.put("wayNumber",3);
            actions.put("sceneNumber",sceneNumber);
            this.setActions(actions);

            //处理好的json对象
            String json = JSONObject.toJSONString(this);
            //将数据发送到mqtt队列中
            JsonToMqtt.sendMQTT(gatewayMac,json);


        } else if ("04".equals(after0FAA)){
            String sceneNumber = StringUtils.substring(data,data.length() - 2, data.length());

            //将actions信息放入json对象中
            Map <String,Object> actions = new HashMap();
            actions.put("controlType","SCENE_NUMBER_GET");
            actions.put("wayNumber",4);
            actions.put("sceneNumber",sceneNumber);
            this.setActions(actions);

            //处理好的json对象
            String json = JSONObject.toJSONString(this);
            //将数据发送到mqtt队列中
            JsonToMqtt.sendMQTT(gatewayMac,json);


        } else if ("05".equals(after0FAA)){
            String sceneNumber = StringUtils.substring(data,data.length() - 2, data.length());

            //将actions信息放入json对象中
            Map <String,Object> actions = new HashMap();
            actions.put("controlType","SCENE_NUMBER_GET");
            actions.put("wayNumber",5);
            actions.put("sceneNumber",sceneNumber);
            this.setActions(actions);

            //处理好的json对象
            String json = JSONObject.toJSONString(this);
            //将数据发送到mqtt队列中
            JsonToMqtt.sendMQTT(gatewayMac,json);


        } else if ("06".equals(after0FAA)){
            String sceneNumber = StringUtils.substring(data,data.length() - 2, data.length());

            //将actions信息放入json对象中
            Map <String,Object> actions = new HashMap();
            actions.put("controlType","SCENE_NUMBER_GET");
            actions.put("wayNumber",6);
            actions.put("sceneNumber",sceneNumber);
            this.setActions(actions);

            //处理好的json对象
            String json = JSONObject.toJSONString(this);
            //将数据发送到mqtt队列中
            JsonToMqtt.sendMQTT(gatewayMac,json);

        }





    }


    public void LiuLuChangJingMianBan_0FAA8A10Set(String gatewayMac, String data){

      this.setOdIndex("0FAA");
      this.setDeviceType("8A");
      this.setProductType("05");
      this.setSwitchState(-100);

        //处理此设备特有的数据
        String afterOdIndex = StringUtils.substring(data,22, 24);
        String state = StringUtils.substring(data,24, 26);


        if ("01".equals(afterOdIndex)){


            //将actions信息放入json对象中
            Map <String,Object> actions = new HashMap();
            actions.put("controlType","SCENE_NUMBER_SET");
            actions.put("wayNumber",1);
            actions.put("state",state);

            this.setActions(actions);

            //处理好的json对象
            String json = JSONObject.toJSONString(this);
            //将数据发送到mqtt队列中
            JsonToMqtt.sendMQTT(gatewayMac,json);

        } else if ("02".equals(afterOdIndex)){

            //将actions信息放入json对象中
            Map <String,Object> actions = new HashMap();
            actions.put("controlType","SCENE_NUMBER_SET");
            actions.put("wayNumber",2);
            actions.put("state",state);

            this.setActions(actions);

            //处理好的json对象
            String json = JSONObject.toJSONString(this);
            //将数据发送到mqtt队列中
            JsonToMqtt.sendMQTT(gatewayMac,json);

        }else if ("03".equals(afterOdIndex)){

            //将actions信息放入json对象中
            Map <String,Object> actions = new HashMap();
            actions.put("controlType","SCENE_NUMBER_SET");
            actions.put("wayNumber",3);
            actions.put("state",state);

            this.setActions(actions);

            //处理好的json对象
            String json = JSONObject.toJSONString(this);
            //将数据发送到mqtt队列中
            JsonToMqtt.sendMQTT(gatewayMac,json);


        }else if ("04".equals(afterOdIndex)){

            //将actions信息放入json对象中
            Map <String,Object> actions = new HashMap();
            actions.put("controlType","SCENE_NUMBER_SET");
            actions.put("wayNumber",4);
            actions.put("state",state);

            this.setActions(actions);

            //处理好的json对象
            String json = JSONObject.toJSONString(this);
            //将数据发送到mqtt队列中
            JsonToMqtt.sendMQTT(gatewayMac,json);

        }else if ("05".equals(afterOdIndex)){

            //将actions信息放入json对象中
            Map <String,Object> actions = new HashMap();
            actions.put("controlType","SCENE_NUMBER_SET");
            actions.put("wayNumber",5);
            actions.put("state",state);

            this.setActions(actions);

            //处理好的json对象
            String json = JSONObject.toJSONString(this);
            //将数据发送到mqtt队列中
            JsonToMqtt.sendMQTT(gatewayMac,json);

        }else if ("06".equals(afterOdIndex)){

            //将actions信息放入json对象中
            Map <String,Object> actions = new HashMap();
            actions.put("controlType","SCENE_NUMBER_SET");
            actions.put("wayNumber",6);
            actions.put("state",state);

            this.setActions(actions);

            //处理好的json对象
            String json = JSONObject.toJSONString(this);
            //将数据发送到mqtt队列中
            JsonToMqtt.sendMQTT(gatewayMac,json);

        }





    }

}
